% Chakram is a subproject of Hexena - Haskell Executable Analyser
% License:			GPL-3
% Maintainer:		Montez Fitzpatrick
% Stability:		Experimental
% Portability:		GHC
% Module:			Hexena.Codec.Parser.ImportDirectory

Import Directory Format

All image files that import symbols have an .idata section
\begin{code}
module Hexena.Codec.Parser.ImportDirectory where

import Data.Word
import Data.Binary.Get

import Hexena.Data.ImportDirectory (ImportDirectory(..), ImportDirectoryTable(..), ImportLookupTable(..),
								    ImportNameHintTable(..), ImportNameHintEntry(..))
import Hexena.Data.ImportDirectory.AMD64 (AMD64(..))
import Hexena.Data.ImportDirectory.X64 (X64(..))

{-
data ImportDirectory = ImportDirectory
	{ _iDirectoryTables :: [ImportDirectoryTable]
	, _iLookupTables :: [ImportLookupTable]
	, _iNameHintTable :: ImportNameHintTable
	} deriving (Show, Eq, Ord)

-- | This is the description for the remainder of the import information.
--
-- The last directory entry is filled with null values to indicate the end of the directory table.
data ImportDirectoryTable = ImportDirectoryTable
	{ _iOrigFirstThunk :: Word32 -- 0 for terminating null import or RVA to original unbound IAT
	, _iTimeDateStamp :: Word32 -- 0 if not bound; -1 if bound and real date/time stamp in IMAGE_DIRECTORY_ENTRY_BOUND_IMPORT
	, _iForwarderChain :: Word32 -- index of first forwarder reference, -1 if no forwarders
	, _iNameRVA :: Word32	-- address of ASCII string that contains the name of the DLL (Addr is relative to image base)
	, _firstThunkTableRVA :: Word32 -- RVA of the IAT
	} deriving (Show, Eq, Ord)

data ImportLookupTable = AMD64
					   | X86
					   deriving (Show, Eq, Ord)

data ImportNameHintTable = ImportNameHintTable
	{ _nhHintNameEntries :: [ImportNameHintEntry] } deriving (Show, Eq, Ord)

data ImportNameHintEntry = ImportNameHintEntry
	{ _nhHint :: Word16
	, _nhName :: [Word8]
	} deriving (Show, Eq, Ord)

-- | Automatically derive a lens for the ImportDirectory data type, which
--   provides getters and setters for that data type.
mkLabels [''ImportDirectory, ''ImportDirectoryTable, ''ImportLookupTable, ''ImportNameHintTable]
-}
\end{code}
